const multer = require("multer");

module.exports = ({
  // 上传目录
  destination: function (req, res, cd) {
    cd(null, 'index/uploads')
  },
  filename: function (req, file, cd) {
    let arr = []
    let src = ""
    let myDate = new Date();
    arr[0] = myDate.getFullYear(), //获取完整的年份(4位,1970-????)
      arr[1] = myDate.getMonth() + 1, //获取当前月份(0-11,0代表1月)
      arr[2] = myDate.getDate(),  //获取当前日(1-31)
      arr[3] = myDate.getHours() + 1, //获取当前小时数(0-23)
      arr[4] = myDate.getMinutes() + 1, //获取当前分钟数(0-59)
      arr[5] = myDate.getSeconds() + 1, //获取当前秒数(0-59)
      arr[6] = myDate.getMilliseconds(); //获取当前毫秒数(0-999) 

    for (let i in arr) {
      src += arr[i]
    }
    let spl = file.originalname.split('.')
    let type = spl[spl.length - 1]
    // console.log(spl);
    cd(null, src + '.' + type)
    // cd(null, file.originalname)
  }
})
